// 上传相关API
window.uploadAPI = {
    // 上传图片
    uploadImage: async (file) => {
        try {
            const formData = new FormData();
            formData.append('file', file);
            const response = await apiClient.post('/api/upload/image', formData, {
                headers: {
                    'Content-Type': 'multipart/form-data'
                }
            });
            return response;
        } catch (error) {
            console.error('上传图片失败:', error);
            throw error;
        }
    },
    
    // 上传文档
    uploadDocument: async (file) => {
        try {
            const formData = new FormData();
            formData.append('file', file);
            const response = await apiClient.post('/api/upload/document', formData, {
                headers: {
                    'Content-Type': 'multipart/form-data'
                }
            });
            return response;
        } catch (error) {
            console.error('上传文档失败:', error);
            throw error;
        }
    },
    
    // 批量上传
    batchUpload: async (files, fileType = 'image') => {
        try {
            const formData = new FormData();
            files.forEach(file => {
                formData.append('files', file);
            });
            formData.append('file_type', fileType);
            const response = await apiClient.post('/api/upload/batch-upload', formData, {
                headers: {
                    'Content-Type': 'multipart/form-data'
                }
            });
            return response;
        } catch (error) {
            console.error('批量上传失败:', error);
            throw error;
        }
    },
    
    // 删除文件
    deleteFile: async (filePath) => {
        try {
            const response = await apiClient.post('/api/upload/delete', { file_path: filePath });
            return response;
        } catch (error) {
            console.error('删除文件失败:', error);
            throw error;
        }
    },
    
    // 上传头像
    uploadAvatar: async (formData) => {
        try {
            const response = await apiClient.post('/auth/upload-avatar', formData, {
                headers: {
                    'Content-Type': 'multipart/form-data'
                }
            });
            return response;
        } catch (error) {
            console.error('上传头像失败:', error);
            throw error;
        }
    }
};
